package com.tuniu.agents.message;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import org.springframework.util.StringUtils;

@Data
@Builder
@AllArgsConstructor
public class MessageLogger {

    public static final String DEFAULT_BEFORE_METHOD_NAME = "before";

    public static final String DEFAULT_AFTER_METHOD_NAME = "after";

    public static final String DEFAULT_THROWABLE_METHOD_NAME = "throwable";

    // Create a MessageLogger instance from ToolLoggerInfo
    public static MessageLogger fromToolLoggerInfo(ToolLoggerInfo info) {
        return MessageLogger.builder()
                .beforeMessage(StringUtils.hasText(info.beforeMessage()) ? info.beforeMessage() : null)
                .afterMessage(StringUtils.hasText(info.afterMessage()) ? info.afterMessage() : null)
                .throwableMessage(StringUtils.hasText(info.throwableMessage()) ? info.throwableMessage() : null)
                .beforeMethod(StringUtils.hasText(info.beforeMethod()) ? info.beforeMethod() : null)
                .afterMethod(StringUtils.hasText(info.afterMethod()) ? info.afterMethod() : null)
                .throwableMethod(StringUtils.hasText(info.throwableMethod()) ? info.throwableMethod() : null)
                .beanName(StringUtils.hasText(info.beanName()) ? info.beanName() : null)
                .build();
    }

    // Constructor with beanName
    public MessageLogger(String beanName) {
        this(null, null, DEFAULT_BEFORE_METHOD_NAME, DEFAULT_AFTER_METHOD_NAME, beanName);
    }

    // Constructor with all parameters
    public MessageLogger(String beforeMessage, String afterMessage, String beforeMethod, String afterMethod, String beanName) {
        this.beforeMessage = beforeMessage;
        this.afterMessage = afterMessage;
        this.beforeMethod = beforeMethod;
        this.afterMethod = afterMethod;
        this.beanName = beanName;
    }

    protected String beforeMessage;

    protected String afterMessage;

    protected String throwableMessage;

    protected String beforeMethod;

    protected String afterMethod;

    protected String throwableMethod;

    protected String beanName;

}
